import { commonPost } from '@api/data'
import { Message, MessageBox, Loading } from "element-ui"
import that from '@/main.js'

/** 调用医保dll**/
export class CallMedInsYn{
    constructor() {
        this.name = 'CHSInterfaceYn';
        this.medinstrade = null;
    }
    async InitAsync() {
        if(typeof(CefSharp) == 'undefined') {
            // eslint-disable-next-line no-console
            console.error("CefSharp is undefined.")
            throw "CefSharp is undefined.";
        } else {
            if(typeof(CHSInterfaceYn) == 'undefined') {
                await CefSharp.BindObjectAsync(this.name);
            }
        }
        this.medinstrade = CHSInterfaceYn;
    }
     /**
     * 交易
     * * @param {objecy} parm  报文对象
     */
    async Trade(keyWord,parm) {
        console.log("医保入参：",keyWord,parm);
		await this.InitAsync();
        if(this.medinstrade == null) {
            await this.InitAsync();
        }
		try{
			console.log('parm',parm)
			var ret = await this.medinstrade.outpatientServiceOcx(keyWord,parm);
			console.log('调用医保dll：',ret)
            return ret;
		}catch(e){
			var _this = that;
			MessageBox.alert("医保结算失败，请移步去窗口结算", {
				confirmButtonText: "确定",
				callback: action => {
					MessageBox.close();
					_this.goBackHome();
				}
			});
			throw '调用医保dll发送错误'+e;
		}
    }
}
function LogError(str) {
    console.log(`%c ${str}`, 'color:red');
}
